package com.nageoffer.jobtrain.admin.controller;

import com.nageoffer.jobtrain.admin.dto.req.ContestAddOjQuestionReqDTO;
import com.nageoffer.jobtrain.admin.dto.req.ContestDeleteOjQuestionReqDTO;
import com.nageoffer.jobtrain.admin.dto.req.ContestSortOjQuestionReqDTO;
import com.nageoffer.jobtrain.admin.service.ContestQuestionService;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 竞赛题目关联控制层
 * author：唐晨
 */
@RestController
@RequiredArgsConstructor
public class ContestQuestionController {
    private final ContestQuestionService contestQuestionService;

    /**
     * 向某个竞赛中新增OJ题目
     */
    @PostMapping("/api/job-train/admin/contest/question/add")
    public Result<Void> addContestOjQuestion(@RequestBody ContestAddOjQuestionReqDTO requestParam) {
        contestQuestionService.addContestOjQuestion(requestParam);
        return Results.success();
    }

    /**
     * 删除竞赛中的OJ题目
     */
    @DeleteMapping("/api/job-train/admin/contest/question/delete")
    public Result<Void> deleteContestOjQuestion(@RequestBody ContestDeleteOjQuestionReqDTO requestParam) {
        contestQuestionService.deleteContestOjQuestion(requestParam);
        return Results.success();
    }

    /**
     * 在进行拖动后重新设置竞赛列表中的OJ题目排序
     */
    @PostMapping("/api/job-train/admin/contest/question/sort")
    public Result<Void> sortContestOjQuestion(@RequestBody ContestSortOjQuestionReqDTO requestParam) {
        contestQuestionService.sortContestOjQuestion(requestParam);
        return Results.success();
    }
}
